﻿using System;
using DOW = DocumentFormat.OpenXml.Wordprocessing;

namespace Tatibah
{
    /// <summary>
    /// Defines the content type of the Run
    /// </summary>
    public enum enumRunType
    {
#pragma warning disable 1591
        Break,
        FieldCode,
        Image,
        Standard,
        Symbol
    }

    public enum enumBreakValues
    {
        Column = DOW.BreakValues.Column,
        Page = DOW.BreakValues.Page,
        TextWrapping = DOW.BreakValues.TextWrapping,
        None
    }

        public enum enumFieldCode
    {
        PAGENUMBER,
        TOTALPAGES
    }
#pragma warning restore 1591
    /// <summary>
    /// This class represent a Run which is text that has the same formatting
    /// </summary>
    public class Run : BaseTextFormatting, iParagraphAppend
    {
        /// <summary>
        /// When set trailing spaces are preserved, default is true
        /// </summary>
        public bool PreserveSpacing = true;

        /// <summary>
        /// The highlighting colour values
        /// </summary>
        public DocumentFormat.OpenXml.Wordprocessing.HighlightColorValues HighLight = DocumentFormat.OpenXml.Wordprocessing.HighlightColorValues.None;
        
        // Private variables
        private string text;
        private enumRunType runType = enumRunType.Standard;
        private enumBreakValues breakValue = enumBreakValues.None;
        private Image image = null;
        private char symbol = '\0';
        private string symbolFont = "";
     

        #region C O N S T R U C T O R S
        /// <summary>
        /// Create a Run from a string
        /// </summary>
        /// <param name="Text"></param>
        public Run(string Text)
        {
            text = Text;
            runType = enumRunType.Standard;
            
        }

        /// <summary>
        /// Create a Run from an Image
        /// </summary>
        /// <param name="ThisImage"></param>
        public Run(Image ThisImage)
        {
            image = ThisImage;
            runType = enumRunType.Image;
        }

        /// <summary>
        /// Create a run from a field code, e.g. NUMPAGES
        /// </summary>
        /// <param name="Value"></param>
        /// <param name="FieldCode"></param>
        public Run(string Value, enumRunType FieldCode)
        {
            if (FieldCode != enumRunType.FieldCode)
                throw new Exception("The Type must be Field Code");

            text = Value;
            runType = FieldCode;
        }

        /// <summary>
        /// Add a break to the run
        /// </summary>
        /// <param name="BreakValue"></param>
        public Run(enumBreakValues BreakValue)
        {
            runType = enumRunType.Break;
            breakValue = BreakValue;
        }

        /// <summary>
        /// Add a symbol to a run
        /// </summary>
        /// <param name="Symbol"></param>
        /// <param name="SymbolFont"></param>
        public Run(char Symbol, string SymbolFont)
        {
            runType = enumRunType.Symbol;
            symbol = Symbol;
            symbolFont = SymbolFont;
        }

        /// <summary>
        /// Create a Run with a field code
        /// </summary>
        /// <param name="FieldCode"></param>
        public Run(enumFieldCode FieldCode)
        {
            runType = enumRunType.FieldCode;
            switch (FieldCode)
            {
                case enumFieldCode.PAGENUMBER:
                    text = " PAGE ";
                    break;
                case enumFieldCode.TOTALPAGES:
                    text = " NUMPAGES ";
                    break;
            }
        }

        #endregion C O N S T R U C T O R S

        #region P R O P E R T I E S
        /// <summary>
        /// Get the MultipleStrings of the Run
        /// </summary>
        public string Text
        {
            get { return text; }
        }

       
        /// <summary>
        /// gets the type of the Run
        /// </summary>
        public enumRunType RunType
        {
            get { return runType; }
        }

        /// <summary>
        /// Gets the image used in the Run, null if no image present
        /// </summary>
        public Image Image
        {
            get { return image; }
        }

        /// <summary>
        /// Get the current break value
        /// </summary>
        public enumBreakValues BreakValue
        {
            get { return breakValue; }
        }

        /// <summary>
        /// Get the current symbol
        /// </summary>
        public char Symbol
        {
            get { return symbol; }
        }

        /// <summary>
        /// Get the current symbol font
        /// </summary>
        public string SymbolFont
        {
            get { return symbolFont; }
        }

        #endregion P R O P E R T I E S

    }
}
